package com.fsp.jianchi.jgjplayer;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2016/5/6.
 */
public class LAdp extends BaseAdapter {
    private List<String> mp3s;
    public int mp3Id;
    private Context context;
    private LayoutInflater mInflater;

    public LAdp(List<String> mp3s, int mp3Id, Context context) {
        this.mp3s=mp3s;
        this.context=context;
        this.mp3Id=mp3Id;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mp3s.size();
    }

    @Override
    public Object getItem(int i) {
        return mp3s.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item, null);
        }
        String txt = mp3s.get(i);

        if(i>mp3Id){
            convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.color_not_played));
        } else {
            convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.color_played));
        }

        TextView title = (TextView) convertView.findViewById(R.id.textView);
        title.setText(txt);
        convertView.setTag(i);
        return convertView;
    }
}
